<?php
/**
 * 物料盘点作业
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/4/18
 * Time: 17:00
 */
namespace App\Http\Controllers\WarehouseManage;
use App\Http\Controllers\ApiController;
use App\Services\Warehouse\InventoryOperationService;
use Illuminate\Http\Request;

class InventoryOperationController extends ApiController{

    protected $InventoryOperationService;
    public function __construct(InventoryOperationService $inventoryOperationService)
    {
        $this->InventoryOperationService=$inventoryOperationService;
    }

    /***
     * 更新物料盘点作业对应物料实物盘点数量并且提交审核
     * 参数说明
     * pdata={"fid":100017,"fbillno":"PDZY000013","note":"测试盘点作业","goodsdata":[{"fentryid":100018,"fcountqty":4990}]}
     * @param Request $request
    @author echa
     * @return mixed
     */
    public function UpdateInventoryOperationAndSubmitAndAudit(Request $request){
        $pdata=$request->pdata;
        if(empty($pdata)){
            return $this->failed('非法请求');
        }
        $pdata=json_decode($pdata,true);
        if(empty($pdata)){
            return $this->failed('参数错误');
        }
        if(count($pdata['goodsdata'])<=0){
            return $this->failed('请输入对应商品的实物盘点数');
        }
        $data=[
            'FID'=>$pdata['fid'],
            'FBillNo'=>$pdata['fbillno'],
            'note'=>$pdata['note'],
            'goodsdata'=>$pdata['goodsdata']
        ];
        try{
            $return=$this->InventoryOperationService->UpdateInventoryOperationAndSubmitAndAudit($data);
            if($return){
                return $this->success($return);
            }else{
                return $this->failed('操作失败');
            }
        }catch (\Exception $exception){
            return $this->failed($exception->getMessage());
        }
    }
}